package com.aboverock.common.domain;

import com.aboverock.common.enums.MessageSourceKey;

/**
 * The Class Result.
 *
 * @author Rock Wang
 */
public class Result {

    /**
     * 成功
     */
    public static final int SUCCESS_CODE = 0;
    /**
     * 失败
     */
    public static final int FAIL_CODE = -1;

    /** The code. */
    private int code;

    /** The message resource key or original message. */
    private String messageKey;

    /** The data. */
    private Object data;

    /**
     * 默认操作成功结果，无返回data.
     *
     * @return the result
     */
    public static Result success() {
        return new Result(SUCCESS_CODE, MessageSourceKey.Common.COMMON_SUCCESS_KEY, null);
    }
    
    /**
     * 自定义操作成功结果，无返回data,传递多消息Key值或者消息.
     *
     * @param messageKey the message key
     * @return the result
     */
    public static Result success(String messageKey) {
        return new Result(SUCCESS_CODE, messageKey, null);
    }

    /**
     * 默认操作成功结果.
     *
     * @param data the data
     * @return the result
     */
    public static Result success(Object data) {
        return new Result(SUCCESS_CODE, MessageSourceKey.Common.COMMON_SUCCESS_KEY, data);
    }

    /**
     * 操作成功结果，传递多消息Key值或者消息.
     *
     * @param messageKey the message resource key or original message
     * @param data the data
     * @return the result
     */
    public static Result success(String messageKey, Object data) {
        return new Result(SUCCESS_CODE, messageKey, data);
    }


    /**
     * 默认操作失败结果，无返回data.
     *
     * @return the result
     */
    public static Result fail() {
        return new Result(FAIL_CODE, MessageSourceKey.Common.COMMON_ERROR_KEY, null);
    }
    
    /**
     * 自定义操作失败结果，无返回data.
     *
     * @param messageKey the message key
     * @return the result
     */
    public static Result fail(String messageKey) {
        return new Result(FAIL_CODE, messageKey, null);
    }

    /**
     * 默认操作失败结果.
     *
     * @param data the data
     * @return the result
     */
    public static Result fail(Object data) {
        return new Result(FAIL_CODE, MessageSourceKey.Common.COMMON_ERROR_KEY, data);
    }
    
    /**
     * 默认操作失败结果，传递多消息Key值或者消息.
     *
     * @param messageKey the message resource key or original message
     * @param data the data
     * @return the result
     */
    public static Result fail(String messageKey, Object data) {
        return new Result(FAIL_CODE, messageKey, data);
    }

    /**
     * Instantiates a new result.
     *
     * @param code the code
     * @param messageKey the message resource key or original message
     * @param data the data
     */
    public Result(int code, String messageKey, Object data) {
        this.code = code;
        this.messageKey = messageKey;
        this.data = data;
    }

    /**
     * Instantiates a new result.
     *
     * @param code the code
     * @param messageKey the message resource key or original message
     */
    public Result(int code, String messageKey) {
        this.code = code;
        this.messageKey = messageKey;
    }

    /**
     * Instantiates a new result.
     */
    public Result() {

    }

    /**
     * Gets the code.
     *
     * @return the code
     */
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    /**
     * the message resource key or original message.
     *
     * @return the message resource key or original message
     */
    public String getMessageKey() {
        return messageKey;
    }

    /**
     * Sets the message resource key or original message.
     *
     * @param messageKey the message resource key or original message
     */
    public void setMessageKey(String messageKey) {
        this.messageKey = messageKey;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
